<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Adminis
  Date: 2025/3/19
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分配权限</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/admin/js/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/bootstrap.min.js"></script>
    <style>

        .cus-container {
            width: 1368px;
            margin-top: 20px;
        }

        #user-add .modal-content {
            padding: 0 20px 20px;
        }

        #user-edit .modal-content {
            padding: 0 20px 20px;
        }

        li {
            list-style: none;
        }

    </style>
</head>
<body>

<div class="container cus-container">
    <!-- 添加用户模态框 -->
    <h3 class="text-center">分配权限</h3>
    <input type="hidden" name="role_id" value="${role_id}">
    <div class="form-group" style="font-size: 16px">
        <c:forEach items="${acl_permissions}" var="acl_permission">
            <div class="menu-list">
                <input ${acl_permission.checked? 'checked' : ''} type="checkbox" value="${acl_permission.perm_id}" class="parent-checkbox">
                    ${acl_permission.name}
                <ul>
                    <c:forEach items="${acl_permission.children}" var="child">
                        <li><input ${child.checked? 'checked' : ''} type="checkbox" value="${child.perm_id}" class="child-checkbox">${child.name}</li>
                    </c:forEach>
                </ul>
            </div>
        </c:forEach>
    </div>
    <a class="btn btn-primary" onclick="save()">保存</a>
</div>

</body>
</html>
<script>

    $(document).ready(function() {
        // 父级复选框全选功能
        $('.parent-checkbox').change(function() {
            var isChecked = $(this).is(':checked');
            $(this).closest('.menu-list').find('.child-checkbox').prop('checked', isChecked);
        });

        function save() {
            var permIds = document.getElementsByTagName('input');
            var perm_ids = "";
            for (var i = 0; i < permIds.length; i++) {
                if (permIds[i].type == 'checkbox' && permIds[i].checked) {
                    perm_ids += permIds[i].value + ',';
                }
            }
            perm_ids = perm_ids.substring(0, perm_ids.length - 1);
            location.href = '${pageContext.request.contextPath}/acl_role/insertAcl_role_permission?role_id=${role_id}&perm_ids=' + perm_ids;
        }
    });

    function save() {
        var permIds = document.getElementsByTagName('input');
        var perm_ids = "";
        for (var i = 0; i < permIds.length; i++) {
            if (permIds[i].type == 'checkbox' && permIds[i].checked) {
                perm_ids += permIds[i].value + ',';
            }
        }
        perm_ids = perm_ids.substring(0, perm_ids.length - 1);
        location.href = '${pageContext.request.contextPath}/acl_role/insertAcl_role_permission?role_id=${role_id}&perm_ids=' + perm_ids;
    }
</script>